<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <link rel="stylesheet" href="style.css">
    <script src="index.js"></script>
</head>

<body>
    <p class="grade">分数：<span id="score01">999999999</span> </p>
    <div class="all">
        <div class="cell n2" id="c00">2</div>
        <div class="cell n4" id="c01">4</div>
        <div class="cell n8" id="c02">8</div>
        <div class="cell n16" id="c03">16</div>
        <div class="cell n32" id="c10">32</div>
        <div class="cell n64" id="c11">64</div>
        <div class="cell n128" id="c12">128</div>
        <div class="cell n256" id="c13">256</div>
        <div class="cell n512" id="c20">512</div>
        <div class="cell n1024" id="c21">1024</div>
        <div class="cell n2048" id="c22">2048</div>
        <div class="cell n4096" id="c23">4096</div>
        <div class="cell n8192" id="c30">8192</div>
        <div class="cell" id="c31"></div>
        <div class="cell" id="c32"></div>
        <div class="cell" id="c33"></div>

    </div>
    <div class="gameover">
        <p>
            游戏结束！<br> 分数：<span id="score02">999999999</span> <br>
            <a href="">再来一次</a>
        </p>
    </div>

    <!-- <script>
        function fireKeyEvent(el, evtType, keyCode) {
            var evtObj;
            if (document.createEvent) {
                if (window.KeyEvent) {//firefox 浏览器下模拟事件
                    evtObj = document.createEvent('KeyEvents');
                    evtObj.initKeyEvent(evtType, true, true, window, true, false, false, false, keyCode, 0);
                } else {//chrome 浏览器下模拟事件
                    evtObj = document.createEvent('UIEvents');
                    evtObj.initUIEvent(evtType, true, true, window, 1);

                    delete evtObj.keyCode;
                    if (typeof evtObj.keyCode === "undefined") {//为了模拟keycode
                        Object.defineProperty(evtObj, "keyCode", { value: keyCode });
                    } else {
                        evtObj.key = String.fromCharCode(keyCode);
                    }

                    if (typeof evtObj.ctrlKey === 'undefined') {//为了模拟ctrl键
                        Object.defineProperty(evtObj, "ctrlKey", { value: true });
                    } else {
                        evtObj.ctrlKey = true;
                    }
                }
                el.dispatchEvent(evtObj);

            } else if (document.createEventObject) {//IE 浏览器下模拟事件
                evtObj = document.createEventObject();
                evtObj.keyCode = keyCode
                el.fireEvent('on' + evtType, evtObj);
            }
        }
        (function () {
            // if (e.keyCode == 37) {
            //     game.moveLeft()
            // }
            // if (e.keyCode == 39) {
            //     game.moveRight()
            // }
            // if (e.keyCode == 38) {
            //     game.moveTop()
            // }
            // if (e.keyCode == 40) {
            //     game.moveButtom()
            // }
            // fireKeyEvent(document.body, 'keydown', 40);
            // var num=[37,38,39,40]
            // setInterval(() => {
            //     for (let i = 0; i < num.length; i++) {
            //         fireKeyEvent(document.body, 'keydown', num[i]);
            //     }
            // }, 200);
            // while (check(window.prompt("璇疯緭鍏ュ€�:", "8192")) === false) {
            //     alert('璇疯緭鍏�2鐨凬娆℃柟锛屼笖X>=2,X<=65536');
            // }

            // while (checkBest(window.prompt("璇疯緭鍏ユ渶楂樺垎:", "318522")) === false) {
            //     alert('璇疯緭鍏ユ暣鏁�');
            // }
            window.localStorage.gameState = '{"grid":{"size":4,"cells":[[{"position":{"x":0,"y":0},"value":' + window.xScore + '},null,null,{"position":{"x":0,"y":3},"value":2}],[{"position":{"x":1,"y":0},"value":2},null,null,null],[null,null,null,null],[null,null,null,null]]},"score":' + window.xbestScore + ',"over":false,"won":false,"keepPlaying":false}';

            //window.localStorage.bestScore = window.xbestScore;

            // alert('鍙互浜嗭紝璇峰埛鏂版湰椤甸潰锛屽紑濮嬪潙浜哄幓锝�');

            location.reload();

            function check(input) {
                var base = Math.log(Math.pow(input, Math.LOG2E));
                console.log(base);
                if (base != parseInt(base) || base < 0 || base > 16) {
                    return false;
                } else {
                    window.xScore = input;
                    return true;
                }
            }

            function checkBest(input) {
                if (input != parseInt(input) || input < 0) {
                    return false;
                } else {
                    window.xbestScore = input;
                    return true;
                }
            }
        })()
    </script> -->
</body>

</html>